﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T> {

    public static T Instance {
        get {
            if (_instance == null) {
                T obj = FindObjectOfType<T>();
                if (obj != null) {
                    _instance = obj;
                } else {
                    GameObject go = new GameObject(typeof(T).Name);
                    _instance = go.AddComponent<T>();
                }
            }
            return _instance;
        }
    }

    static T _instance;

}

